package com.starryx.sim.mvc.controller;


import io.netty.handler.codec.http.HttpMethod;

/**
 * 请求映射包装类
 */
public class RequestMappingWrapper {

    /**
     * 请求路径
     */
    private String uri;

    /**
     * 请求方法
     */
    private HttpMethod httpMethod;

    public RequestMappingWrapper(String uri, HttpMethod httpMethod) {
        this.uri = uri;
        this.httpMethod = httpMethod;
    }

    public RequestMappingWrapper() {
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }

    public HttpMethod getHttpMethod() {
        return httpMethod;
    }

    public void setHttpMethod(HttpMethod httpMethod) {
        this.httpMethod = httpMethod;
    }

    @Override
    public String toString() {
        return "RequestMappingWrapper{" +
                "uri='" + uri + '\'' +
                ", httpMethod=" + httpMethod +
                '}';
    }

    /* 重写 hashCode 方法和 equals 方法用于方便 map 使用 */

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + (uri == null ? 0 : uri.hashCode());
        result = 31 * result + (httpMethod == null ? 0 : httpMethod.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof RequestMappingWrapper) {
            RequestMappingWrapper wrapper = (RequestMappingWrapper) obj;
            return this.getUri().equals(wrapper.getUri()) && this.getHttpMethod().equals(wrapper.getHttpMethod());
        } else {
            return false;
        }
    }
}
